package com.bentley.kotlindemo.ui.kits.toptab

import android.os.Bundle
import com.bentley.kotlindemo.R
import com.bentley.kotlindemo.base.BaseActivity
import com.bentley.kotlindemo.databinding.ActivityToptabBinding
import com.google.android.material.tabs.TabLayoutMediator

/**
 * <pre>
 *  ┌────────────────────────────────────────────
 *  │ @author  Lee  @date 2021/3/29 15:26
 *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
 *  │ @desc
 *  └────────────────────────────────────────────
 * </pre>
 */
class ToptabActivity :BaseActivity <ActivityToptabBinding,ToptabModel>(){
    override fun initView(savedInstanceState: Bundle?) {

        val tabLayout = dataBinding.tabs
        val viewPager = dataBinding.viewPager

        viewPager.adapter = ViewPagerAdapter()

        // Set the icon and text for each tab
        TabLayoutMediator(tabLayout, viewPager) { tab, position ->
            tab.setIcon(getTabIcon(position))
            tab.text = getTabTitle(position)
        }.attach()

//        (this as AppCompatActivity).setSupportActionBar(dataBinding.toolbar)
    }

    private fun getTabIcon(position: Int): Int {
        return when (position) {
            MY_GARDEN_PAGE_INDEX -> R.drawable.garden_tab_selector
            PLANT_LIST_PAGE_INDEX -> R.drawable.plant_list_tab_selector
            else -> throw IndexOutOfBoundsException()
        }
    }

    private fun getTabTitle(position: Int): String? {
        return when (position) {
            MY_GARDEN_PAGE_INDEX -> "花园列表"
            PLANT_LIST_PAGE_INDEX -> "植物列表"
            else -> null
        }
    }

    override fun getLayoutId() = R.layout.activity_toptab
}